package com.hongyuan.coach.ui.home.adapter;

import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.hongyuan.coach.R;
import com.hongyuan.coach.data.md5.BaseUtil;
import com.hongyuan.coach.ui.home.beans.StudentsBeans;
import com.makeramen.roundedimageview.RoundedImageView;

import java.util.ArrayList;

public class StudentsAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {

    public static final int TYPE_ONE = 0;
    public static final int TYPE_TWO = 1;

    public StudentsAdapter() {
        super(new ArrayList<>());
        addItemType(TYPE_ONE, R.layout.item_students);
        addItemType(TYPE_TWO, R.layout.item_students_course);
    }

    @Override
    protected void convert(BaseViewHolder helper, MultiItemEntity item) {
        switch (helper.getItemViewType()) {
            case TYPE_ONE:
                StudentsBeans.ListBean oneBean = (StudentsBeans.ListBean) item;

                RequestOptions options = new RequestOptions().placeholder(R.mipmap.default_head_img).error(R.mipmap.default_head_img).centerCrop();
                Glide.with(mContext).load(oneBean.getMi_head()).apply(options).into((RoundedImageView)helper.getView(R.id.headImg));

                helper.setImageResource(R.id.sexMark,oneBean.getMi_sex()==1 ? R.mipmap.person_boby_mark_img : R.mipmap.person_girl_mark_img);

                if(BaseUtil.isValue(oneBean.getMi_realname())){
                    helper.setText(R.id.name,oneBean.getMi_realname());
                }else{
                    helper.setText(R.id.name,oneBean.getM_name());
                }

                helper.itemView.setOnClickListener(view -> {
                    int pos = helper.getAdapterPosition();
                    if (oneBean.isExpanded()) {
                        //收起
                        collapse(pos);
                        //helper.setImageResource(R.id.dowImg,R.mipmap.vtwo_login_eye_outline_img_);
                    } else {
                        //打开
                        expand(pos);
                        //helper.setImageResource(R.id.dowImg,R.mipmap.vtwo_login_eye_off_img_);
                    }
                });
                break;
            case TYPE_TWO:
                StudentsBeans.ListBean.CourseListBean courseListBean = (StudentsBeans.ListBean.CourseListBean) item;
                helper.setText(R.id.courseName,courseListBean.getCp_name()+"\t("+courseListBean.getHave_num()+"/"+courseListBean.getOcp_num()+")");

                if(BaseUtil.isValue(courseListBean.getAdd_date())){
                    //helper.setText(R.id.timeText, "购买时间:"+TimeUtil.formatDate(courseListBean.getAdd_date(),TimeUtil.dateFormatYMD,TimeUtil.dateFormatDotYMDHM));
                    helper.setText(R.id.timeText, "购买时间:"+courseListBean.getAdd_date());
                }

                if(courseListBean.isSelect()){
                    helper.setImageResource(R.id.checkImg,R.mipmap.vtwo_login_xieyi_select_img);
                }else{
                    helper.setImageResource(R.id.checkImg,R.mipmap.vtwo_login_xieyi_default_img);
                }

                helper.addOnClickListener(R.id.childBox);

                break;
        }
    }
}
